
package net.swa.index.web.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Required;
import net.swa.dewei.beans.entity.OneCard;
import net.swa.dewei.service.OneCardService;
import net.swa.system.service.ICommonService;
import net.swa.util.DateUtils;

/**
 * 激活一卡通
 * 
 * @author Administrator
 * 
 */
public class OneCardActiveAction extends AbstractBaseIndexAction
{
    private static final long serialVersionUID = 7868090805552756795L;

    /** 公用方法接口 */
    private ICommonService commonService;

    private OneCardService oneCardService;

    //实体类id
    private Long id;

    //广告实体类
    private OneCard model;

    /**获取方式类型**/
    private String oncardListJson;

    /**进入激活界面*/
    public String init()
    {
        model = new OneCard();
        //        List<Dict> oneCardTypes = commonService.search("title", Const.DICT_KEY_ONCARD_GETTYPE, Dict.class, null, "dictPaixu", "asc");
        //        JSONArray ja = JSONArray.fromObject(oneCardTypes);
        //        oncardListJson = ja.toString();
        return "init";
    }

    /**激活操作
     * @throws Exception **/
    public String saveStateActive() throws Exception
    {
        Map<String, Object> map = null;
        if (null != model && null == model.getId())
        {
            model.setCrateDate(DateUtils.getCurrDate(null));
            map = oneCardService.add(model);
        }else{
            outError("系统出错");
        }
        if (null==map)
        {
           map=new HashMap<String, Object>();
           map.put("success", false);
           map.put("message", "保存出错");
        }
        outJson(map);
        return null;

    }

    /**检测卡是否已经存在操作
     * @throws Exception **/
    public String checkOneCard() throws Exception
    {
        List<OneCard> list = commonService.search("cardNo", model.getCardNo(), OneCard.class);
        outString((list.size() == 0) + "");
        return null;
    }

    @Required
    @Resource
    public void setCommonService(ICommonService commonService)
    {
        this.commonService = commonService;
    }

    public ICommonService getCommonService()
    {
        return commonService;
    }

    @Required
    @Resource
    public void setOneCardService(OneCardService oneCardService)
    {
        this.oneCardService = oneCardService;
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public OneCard getModel()
    {
        return model;
    }

    public void setModel(OneCard model)
    {
        this.model = model;
    }

    public String getOncardListJson()
    {
        return oncardListJson;
    }

    public void setOncardListJson(String oncardListJson)
    {
        this.oncardListJson = oncardListJson;
    }

}
